﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using O2S.Components.PDFView4NET;

namespace Framwork.Winform.Test
{
    public partial class FrmPDFShow : UserControl
    {
        
        public FrmPDFShow()
        {
            InitializeComponent();
        }
        public string LoadFilePath
        {
            set
            {
                LoadFile(value);
            }
        }
        //加载pdf文件
        private void LoadFile(string filepath)
        {
            try
            {
                string pdfPath = Path.GetDirectoryName(filepath) + "\\" + Path.GetFileNameWithoutExtension(filepath) + ".pdf";
                switch (Path.GetExtension(filepath).ToLower())
                {
                    case ".doc":
                        OfficeToPdf.DOCConvertToPDF(filepath, pdfPath);
                        break;
                    case ".xls":
                        OfficeToPdf.XLSConvertToPDF(filepath, pdfPath);
                        break;
                    case ".ppt":
                        OfficeToPdf.PPTConvertToPDF(filepath, pdfPath);
                        break;
                }
                pdfPageView1.Document = pdfDocument1;
                pdfDocument1.Load(pdfPath);
                this.pdfPageView1.PageDisplayLayout = PDFPageDisplayLayout.OneColumn;

            }
            catch (Exception ex)
            {
                MessageBox.Show("转换pdf错误" + ex.Message);
            }
        }
        private void tbtnZoomFitHeight_Click_1(object sender, EventArgs e)
        {
            pdfPageView1.ZoomMode = PDFZoomMode.FitHeight;
        }
        //
        private void tbtnZoomFitWidth_Click(object sender, EventArgs e)
        {
            pdfPageView1.ZoomMode = O2S.Components.PDFView4NET.PDFZoomMode.FitWidth;
        }
        //缩小
        private void tbynZoomOut_Click(object sender, EventArgs e)
        {
            pdfPageView1.WorkMode = O2S.Components.PDFView4NET.UserInteractiveWorkMode.ZoomOut;
        }
        //放大
        private void tbtnZoomIn_Click(object sender, EventArgs e)
        {
            pdfPageView1.WorkMode = O2S.Components.PDFView4NET.UserInteractiveWorkMode.ZoomIn;
        }
        //鼠标拖动文件
        private void tbtnPanScan_Click(object sender, EventArgs e)
        {
            this.pdfPageView1.Cursor = Cursors.Hand;
            pdfPageView1.WorkMode = UserInteractiveWorkMode.PanAndScan;
        }
    }
}

